//
// Created by Gu,Xiuzhong on 2020/10/30.
//

#include "log-util.h"

extern "C"
JNIEXPORT void JNICALL
Java_com_example_ndkjnidemo_home_basetype_JNIData_data(
        JNIEnv *env,
        jobject thiz,
        jbyte b,
        jchar c,
        jboolean j_bool,
        jshort s,
        jint i,
        jfloat f,
        jdouble d,
        jlong l,
        jfloatArray floats) {

    LOGI("byte=%d", b);
    LOGI("jchar=%c", c);
    LOGI("jboolean=%d", j_bool);
    LOGI("jshort=%d", s);
    LOGI("jint=%d", i);
    LOGI("jfloat=%f", f);
    LOGI("jdouble=%lf", d);
    LOGI("jlong=%lld", l);

    jfloat *float_p = env->GetFloatArrayElements(floats, nullptr);
    jsize size = env->GetArrayLength(floats);
    for (int index = 0; index < size; index++) {
        LOGI("floats[%d]=%lf", index, *(float_p++));
    }
    // mode:释放模式,通常使用 0。有三种
    // 0 将内容复制回来并释放原生数组
    // JNI_COMMIT 将内容复制回来但不释放原生数组，一般用于周期性更新数组
    // JNI_ABORT 释放原生数组但不将内容复制回来
    env->ReleaseFloatArrayElements(floats, float_p, 0);
}